package com.wangshuqi.boot.controller;

import com.wangshuqi.boot.domain.*;
import com.wangshuqi.boot.result.ResultMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @PostMapping("/save")
    public ResultMessage save(@RequestBody User user) {
        if (user.getUsername() == null) {
            return ResultMessage.fail(500, "用户名不能为空");
        }
        System.out.println(user.toString());
        return ResultMessage.success();
    }

    @PostMapping("/post")
    public ResultMessage post(@RequestBody ParamForGet param) {
        String print = "orderId = " + param.getOrderId() + "; depotId = " + param.getDepotId();
        System.out.println(print);
        param.getOrderList().forEach(System.out::println);
        param.getVehicleList().forEach(System.out::println);
        return ResultMessage.success();
    }


    @GetMapping("/getParamObject")
    public ResultMessage getParamObject(@RequestParam("param") ParamForGet param) {
        String print = "orderId = " + param.getOrderId() + "; depotId = " + param.getDepotId();
        System.out.println(print);
        param.getOrderList().forEach(System.out::println);
        param.getVehicleList().forEach(System.out::println);
        return ResultMessage.success();
    }

    @GetMapping("/getParamJsonStr")
    public ResultMessage getParamJsonStr(@RequestBody ParamForGet param) {
        String print = "orderId = " + param.getOrderId() + "; depotId = " + param.getDepotId();
        System.out.println(print);
        param.getOrderList().forEach(System.out::println);
        param.getVehicleList().forEach(System.out::println);
        return ResultMessage.success();
    }


    @PostMapping("/warehouse")
    public ResultMessage warehouse(@RequestParam("key") String key, @RequestBody List<WarehouseInfoDTO> warehouseInfoDTOS) {
        System.out.println("key: " + key);
        System.out.println("RCes8iFj9FcUieu1".equals(key));
        warehouseInfoDTOS.forEach(System.out::println);
        return ResultMessage.success();
    }

    @PostMapping("/shop")
    public ResultMessage shop(@RequestParam("key") String key, @RequestBody List<ShopDataDTO> shopDataDTOList) {
        System.out.println("key: " + key);
        System.out.println("RCes8iFj9FcUieu1".equals(key));
        shopDataDTOList.forEach(System.out::println);
        return ResultMessage.success();
    }

    @PostMapping("/order")
    public ResultMessage order(@RequestParam("key") String key, @RequestBody OrderArrangeDTO orderArrangeDTO) {
        log.info("key: " + key);
        Boolean equals = "RCes8iFj9FcUieu1".equals(key);
        log.info(equals.toString());
        log.info("orderId: {},depotId: {}", orderArrangeDTO.getOrderId(), orderArrangeDTO.getDepotId());
        orderArrangeDTO.getOrderList().forEach(System.out::println);
        orderArrangeDTO.getVehicleList().forEach(System.out::println);
        return ResultMessage.success();
    }
}
